package com.topvision.controller;

import com.topvision.common.response.SuccessResponse;
import com.topvision.domain.SysProduct;
import com.topvision.service.SysProductService;
import com.topvision.utils.web.HeaderUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/product")
@Api(value = "产品服务API", description = "产品服务展示相关")
@Slf4j
public class SysProductController {

    @Autowired
    private SysProductService sysProductService;

    @GetMapping("/list/{parentId}")
    public ResponseEntity products(@PathVariable Long parentId) {
        Optional<List<SysProduct>> list = sysProductService.findByParentId(parentId);
        return list.map(lists -> {

               return ResponseEntity.ok().body(SuccessResponse.of(lists));

         }).orElse(ResponseEntity.ok().body(SuccessResponse.of("empty")));
    }




}
